﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PalFramework;
using PalFramework.Template;

namespace PalBattleEmulator.Template.Unit
{
    public class EnemyTmpl : PalObjectTmpl, IEnemyTmpl
    {
        public override void LoadData(Dictionary<string, string> data)
        {
            foreach (string key in data.Keys)
            {
                if(dictionary.ContainsKey(key))
                {
                    int type = dictionary[key];
                    string value = data[key];
                    switch (type)
                    {
                        case ID:
                            Id = Convert.ToInt32(value);
                            break;
                        case NAME:
                            Name = value;
                            break;
                        case SPRITE:
                            Sprite = value;
                            break;
                        case IDLE_FRAMES:
                            graphicInfo.IdleFrames = Convert.ToInt32(value);
                            break;
                        case CAST_FRAMES:
                            graphicInfo.CastFrames = Convert.ToInt32(value);
                            break;
                        case ATTACK_FRAMES:
                            graphicInfo.AttackFrames = Convert.ToInt32(value);
                            break;
                        case IDLE_SPAN:
                            graphicInfo.IdleSpan = Convert.ToInt32(value);
                            break;
                        case DATA5:
                            graphicInfo.Data5 = Convert.ToInt32(value);
                            break;
                        case Y_REVISE:
                            graphicInfo.YRevice = Convert.ToInt32(value);
                            break;
                    }
                }
                
            }
        }

        private string sprite;

        public string Sprite
        {
            get
            {
                return sprite;
            }
            set
            {
                sprite = value;
            }
        }

        private EnemyGraphicInfo graphicInfo;

        public EnemyGraphicInfo GraphicInfo
        {
            get { return graphicInfo; }
            set { graphicInfo = value; }
        }

        public const int ID = 0;
        public const int NAME = 1;
        public const int SPRITE = 2;
        public const int IDLE_FRAMES = 3;
        public const int CAST_FRAMES = 4;
        public const int ATTACK_FRAMES = 5;
        public const int IDLE_SPAN = 6;
        public const int DATA5 = 7;
        public const int Y_REVISE = 8;

        private static Dictionary<string, int> dictionary;

        static EnemyTmpl()
        {
            dictionary = new Dictionary<string, int>();
            dictionary.Add("id", ID);
            dictionary.Add("name", NAME);
            dictionary.Add("sprite", SPRITE);
            dictionary.Add("idle_frames", IDLE_FRAMES);
            dictionary.Add("cast_frames", CAST_FRAMES);
            dictionary.Add("attack_frames", ATTACK_FRAMES);
            dictionary.Add("idle_span", IDLE_SPAN);
            dictionary.Add("data5", DATA5);
            dictionary.Add("y_revise", Y_REVISE);
        }
    }
}
